import cv2
import matplotlib.pyplot as plt
img = cv2.imread(r"D:\l'j't\code\pycharm\learning-python\AI\images\005.jpeg")
template = cv2.imread(r"D:\l'j't\code\pycharm\learning-python\AI\images\005_template.png", cv2.IMREAD_GRAYSCALE)

img1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

h, w = template.shape

res = cv2.matchTemplate(img1, template, cv2.TM_CCOEFF_NORMED)
plt.imshow(res, cmap='gray')
plt.title("Matching Result")
plt.axis('off')
plt.show()
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
top_left = min_loc
bottom_right = (top_left[0] + w, top_left[1] + h)
cv2.rectangle(img, top_left, bottom_right, (0, 0, 255), 2)
cv2.imshow("Detected Range", img)
cv2.waitKey(0)